//新建弹框
function addServer(){
	layer.open({
        move: false,
        type: 2,
        title: '新建服务',
        area: ['800px', '350px'],
        content: 'j_clean_add.html',
        btn: ['保存','取消'],
        btnAlign: 'c',
        yes: function (index, layero) {
            var openWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            var form= openWin.submitForm();
            if(!form){
                layer.close(index);
            }
        }, cancel: function (index) {
            layer.close(index);
        }
    });
}
$(function () {
    $('#serverName').focus();
    //重置表单
    $("#searchReset").on("click",function(){
        $('#serverName').val('');
        $('#serverCode').val('');
        $('#cleanTable').bootstrapTable('refresh');
    });
    //渲染表格
    var columns = cleanList.columnsInit();
    var table = cleanList.gridInit(columns);
    var datas = cleanList.dataInit();
    $("#cleanTable").bootstrapTable("append",datas);
    //点击删除按钮信息弹出框
    $("#del-btn").click(function(){
        var len = $("#cleanTable input:checked").length;
        if (len == 0) {
            //未选中数据提示框
            layer.msg('请选择数据',  {time:1000});
        } else {
            layer.confirm('确定要删除这条数据吗？',
                {icon: 3, title: '提示', area: '300px', btnAlign: 'c'}, function (index) {
                    layer.close(index);
                });
        }

    });
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var cleanList = {
        columnsInit:function(){
            return  [{
                field: 'id',
                title: '序号',
                width:'2%',
                align:'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },{
                field: 'serverName',
                valign: 'middle',
                title: '服务名称'
            }, {
                field: 'serverCode',
                valign: 'middle',
                title: '服务编码',
                sortable : true
            }, {
                field: 'rowSort',
                valign: 'middle',
                title: '排序'
            },{
                checkbox: true
            },{
                field: 'edit',
                title: '编辑',
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    return [
                        '<li><a href="javascript:void(0)" onclick="addServer();" title="编辑" class="opt-icon"><i class="glyphicon glyphicon-pencil"></i></a></li>',
                    ].join('');
                }

            }]
        },
        gridInit:function(columns){
            return $("#cleanTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                pageNumber: 1,
                pageSize: 10,
                pageList: [
                    10, 30, 50, 100, 200
                ]
            })

        },
        dataInit:function(){
            return  [{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            },{
                serverName: '任务组',
                serverCode: 'ELE-JFPG-A1',
                rowSort:'111'
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = cleanList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return cleanList;});
    } else {
        !('plugin' in _global) && (_global.cleanList = cleanList);
    }
}());